public class Demo10 {
    public static void main(String[] args) throws InterruptedException {
        //t线程等待主线程
        Thread mainThread =Thread.currentThread();//拿到主线程对象

        Thread t =new Thread(()->{
            System.out.println("t线程开始等待...");
            try {
                mainThread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("t线程等待结束");
        });
        t.start();
        Thread.sleep(2000);
        System.out.println("main线程执行结束.");

    }
}
